/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.prep.view.command;

import java.util.Vector;

import javax.swing.JInternalFrame;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.ui.rich.prep.view.DesktopPrep;
import br.ufmg.dees.insane.ui.rich.prep.view.InterfacePrep;

/** The redo command.
 *
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @since February 2004
 */
public class RedoCommand implements Command {
	
    private Vector<Command> redoList = new Vector<Command>();
    private InterfacePrep intFrame;
    private DesktopPrep desktop;
    
//*****************************************************************************
	
    /** Constructor method. */
    public RedoCommand(JInternalFrame parent) {
        this.intFrame = (InterfacePrep)parent;
    }
    
    public RedoCommand() {}
	
//*****************************************************************************
	
	/** Adds a command to the redo list.
	*@param cmd The command to be added.
	*/
    public void add(Command cmd) {
        if (!(cmd instanceof RedoCommand)) {
            redoList.add(cmd);
        }
    }
    
//*****************************************************************************
	
	/** Clears the redo list.*/
    public void clear() {
        redoList.clear();
    }
    
//*****************************************************************************
	
	/** Execute method. */
    public void execute() {
        int index = redoList.size() - 1;
        if (index >= 0) {
            Command cmd = (Command)redoList.get(index);
            desktop.addToUndo(cmd);
            cmd.redo();
            redoList.remove(index);
            intFrame.getView().getDrawingArea().repaint();
        }
        else {
        	desktop.getDesktopTextArea().addText("Nothing to redo.");
		}
		
        if (redoList.size() == 0) {
        	desktop.nothingToRedo();
        }
    }
    
//*****************************************************************************
	
	/** Impossible to undo - not implemented. */
    public void undo() {
    }
    
//*****************************************************************************
	
	/** Impossible to redo - not implemented. */
    public void redo() {
    }
    
//*****************************************************************************

	public void setParent(InterfacePrep currentintFrame, DesktopPrep dsk)
	{
		this.intFrame = currentintFrame;
		this.desktop = (DesktopPrep)dsk;
	} 
	
//  ****************************************************************************
}

